<?php
 add_action("admin_init", "wpbl_init");
function wpbl_init(){
  add_meta_box("bookid-meta", "Book ID", "bookid", "library", "normal", "high");
  add_meta_box("details-meta", "Details Info", "details", "library", "normal", "high");
}
 
function bookid(){
  global $post;
  $custom = get_post_custom($post->ID);
  $bookid = $custom["bookid"][0];
  ?><p>
  <label>Book ID:</label>
   <input type="text" cols="30" rows="1" name="bookid"><?php echo $bookid; ?></input></p>
  <?php
}
function details() {
  global $post;
  $custom = get_post_custom($post->ID);
  $from = $custom["from"][0];
  $price = $custom["price"][0];
  $receive_date = $custom["receive_date"][0];
   $list_date = $custom["bookdate"][0]; 
  ?>
  <p><label>Received From:</label><br />
  <input type="text" cols="30" rows="1" name="from" id="from"><?php echo $from; ?></input></p>
  <p><label>Received Date:</label><br />
  <input type="text" cols="30" rows="1" name="receive_date"><?php echo $receive_date; ?></input></p>
  <p><label>Listed Date:</label><br />
  <input type="text" cols="30" rows="1" name="bookdate" id="bookdate"  value="<?php echo $list_date; ?>" onfocus="if (this.value == '<?php the_time('j, M, Y'); ?>') {this.value = '';}" onblur="if (this.value == '') {this.value = '<?php the_time('j, M, Y'); ?>';}"/></p>
  <p><label>Price:</label><br />
  <input type="text" cols="30" rows="1" name="price"><?php echo $price; ?></input></p>
  <?php
}
add_action('save_post', 'save_details');
function save_details(){
  global $post;
 
  update_post_meta($post->ID, "bookid", $_POST["bookid"]);
  update_post_meta($post->ID, "receive_date", $_POST["receive_date"]);
  update_post_meta($post->ID, "from", $_POST["from"]);
  update_post_meta($post->ID, "price", $_POST["price"]);
  update_post_meta($post->ID, "bookdate", $_POST["bookdate"]);
  update_post_meta($post->ID, "authors", $_POST["bookauthors"]);
  update_post_meta($post->ID, "publishers", $_POST["bookpublishers"]);
  update_post_meta($post->ID, "editions", $_POST["bookeditions"]);
  update_post_meta($post->ID, "classcat", $_POST["classcat"]);
}
add_action("manage_posts_custom_column",  "library_custom_columns");
add_filter("manage_edit-library_columns", "library_edit_columns");
 
function library_edit_columns($columns){
  $columns = array(
    "cb" => "<input type=\"checkbox\" />",
    "title" => __("Book Title"),
	"bookid" => "Book ID",
    "classcat" => "Class/Category",
    "authors" => "Authors",
    "pub" => "Publishers",
	"date" => "ListDate",
  );
 
  return $columns;
}
function library_custom_columns($column){
  global $post;
 
  switch ($column) {
      case "bookid":
      $custom = get_post_custom();
      echo $custom["bookid"][0];
      break;
    case "classcat":
      echo get_the_term_list($post->ID, 'classcat', '', ', ','');
      break;
    case "authors":
      echo get_the_term_list($post->ID, 'authors', '', ', ','');
      break;
    case "pub":
      echo get_the_term_list($post->ID, 'publishers', '', ', ','');
      break;
      case "date":
      $custom = get_post_custom();
      echo $custom["bookdate"][0];
      break;
  }
}
?>